﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

using Projekt.Cameras;

/*
 * Opisuje prymityw przedstawiający prostopadłościan.
 */
namespace Projekt.Models.Primitives
{
    public class Box : Primitive
    {
        /// <summary>
        /// Tworzy prostopadłościan o podanych parametrach
        /// </summary>
        /// <param name="Position">Punkt centralny</param>
        /// <param name="Rotation">Wektor obrotu</param>
        /// <param name="Scale">Wymiary</param>
        public Box(Vector3 Position, Vector3 Rotation, Vector3 Scale, Color color, GraphicsDevice graphicsDevice, Engine game)
            : base(graphicsDevice, game)
        {
            this.Position = Position;
            this.Rotation = Rotation;
            this.Scale = Scale;
            this.game.Components.Add(this);

            vertices.Add(new VertexPositionColor[20]);

            //front
            vertices[0][0].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][0].Color = color;
            vertices[0][1].Position = new Vector3(0.5f, 0.5f, 0.5f);
            vertices[0][1].Color = color;
            vertices[0][2].Position = new Vector3(0.5f, -0.5f, 0.5f);
            vertices[0][2].Color = color;
            vertices[0][3].Position = new Vector3(-0.5f, -0.5f, 0.5f);
            vertices[0][3].Color = color;
            vertices[0][4].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][4].Color = color;

            //back
            vertices[0][5].Position = new Vector3(-0.5f, 0.5f, -0.5f);
            vertices[0][5].Color = color;
            vertices[0][6].Position = new Vector3(0.5f, 0.5f, -0.5f);
            vertices[0][6].Color = color;
            vertices[0][7].Position = new Vector3(0.5f, -0.5f, -0.5f);
            vertices[0][7].Color = color;
            vertices[0][8].Position = new Vector3(-0.5f, -0.5f, -0.5f);
            vertices[0][8].Color = color;
            vertices[0][9].Position = new Vector3(-0.5f, 0.5f, -0.5f);
            vertices[0][9].Color = color;

            //top
            vertices[0][10].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][10].Color = color;
            vertices[0][11].Position = new Vector3(0.5f, 0.5f, 0.5f);
            vertices[0][11].Color = color;
            vertices[0][12].Position = new Vector3(0.5f, 0.5f, -0.5f);
            vertices[0][12].Color = color;
            vertices[0][13].Position = new Vector3(-0.5f, 0.5f, -0.5f);
            vertices[0][13].Color = color;
            vertices[0][14].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][14].Color = color;

            //bottom
            vertices[0][15].Position = new Vector3(-0.5f, -0.5f, 0.5f);
            vertices[0][15].Color = color;
            vertices[0][16].Position = new Vector3(0.5f, -0.5f, 0.5f);
            vertices[0][16].Color = color;
            vertices[0][17].Position = new Vector3(0.5f, -0.5f, -0.5f);
            vertices[0][17].Color = color;
            vertices[0][18].Position = new Vector3(-0.5f, -0.5f, -0.5f);
            vertices[0][18].Color = color;
            vertices[0][19].Position = new Vector3(-0.5f, -0.5f, 0.5f);
            vertices[0][19].Color = color;
        }

        /// <summary>
        /// Tworzy prostopadłościan na podstawie punktu najmniejszego i największego
        /// </summary>
        /// <param name="Min">Pozycja punktu najmniejszego, o najmniejszych wartościach na wszystkich 3 osiach</param>
        /// <param name="Max">Pozycja punktu największego, o największych wartościach na wszystkich 3 osiach</param>
        public Box(Vector3 Min, Vector3 Max, Color color, GraphicsDevice graphicsDevice, Engine game)
            : base(graphicsDevice, game)
        {
            this.Position = Min + (Max - Min) / 2f;
            this.Rotation = Vector3.Zero;
            this.Scale = new Vector3(Max.X - Min.X, Max.Y - Min.Y, Max.Z - Min.Z);
            this.game.Components.Add(this);

            vertices.Add(new VertexPositionColor[20]);

            //front
            vertices[0][0].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][0].Color = color;
            vertices[0][1].Position = new Vector3(0.5f, 0.5f, 0.5f);
            vertices[0][1].Color = color;
            vertices[0][2].Position = new Vector3(0.5f, -0.5f, 0.5f);
            vertices[0][2].Color = color;
            vertices[0][3].Position = new Vector3(-0.5f, -0.5f, 0.5f);
            vertices[0][3].Color = color;
            vertices[0][4].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][4].Color = color;

            //back
            vertices[0][5].Position = new Vector3(-0.5f, 0.5f, -0.5f);
            vertices[0][5].Color = color;
            vertices[0][6].Position = new Vector3(0.5f, 0.5f, -0.5f);
            vertices[0][6].Color = color;
            vertices[0][7].Position = new Vector3(0.5f, -0.5f, -0.5f);
            vertices[0][7].Color = color;
            vertices[0][8].Position = new Vector3(-0.5f, -0.5f, -0.5f);
            vertices[0][8].Color = color;
            vertices[0][9].Position = new Vector3(-0.5f, 0.5f, -0.5f);
            vertices[0][9].Color = color;

            //top
            vertices[0][10].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][10].Color = color;
            vertices[0][11].Position = new Vector3(0.5f, 0.5f, 0.5f);
            vertices[0][11].Color = color;
            vertices[0][12].Position = new Vector3(0.5f, 0.5f, -0.5f);
            vertices[0][12].Color = color;
            vertices[0][13].Position = new Vector3(-0.5f, 0.5f, -0.5f);
            vertices[0][13].Color = color;
            vertices[0][14].Position = new Vector3(-0.5f, 0.5f, 0.5f);
            vertices[0][14].Color = color;

            //bottom
            vertices[0][15].Position = new Vector3(-0.5f, -0.5f, 0.5f);
            vertices[0][15].Color = color;
            vertices[0][16].Position = new Vector3(0.5f, -0.5f, 0.5f);
            vertices[0][16].Color = color;
            vertices[0][17].Position = new Vector3(0.5f, -0.5f, -0.5f);
            vertices[0][17].Color = color;
            vertices[0][18].Position = new Vector3(-0.5f, -0.5f, -0.5f);
            vertices[0][18].Color = color;
            vertices[0][19].Position = new Vector3(-0.5f, -0.5f, 0.5f);
            vertices[0][19].Color = color;
        }

        /// <summary>
        /// Oblicza macierz transformacji.
        /// </summary>

        public override string ToString()
        {
            return base.ToString() + "." + "box";
        }
    }
}
